package bupt.party.online.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Set;

import bupt.party.online.dao.IBranchDao;
import bupt.party.online.dao.ILearnRecordDao;
import bupt.party.online.dto.BranchStudyRecordDTO;
import bupt.party.online.dto.PartyStudyRecordDTO;
import bupt.party.online.dto.PersonStudyRecordDTO;
import bupt.party.online.model.LearnRecord;
import bupt.party.online.service.ILearnRecordService;

public class LearnRecordServiceImpl implements ILearnRecordService{

	private ILearnRecordDao learnRecordDao;
	private IBranchDao branchDao;

	public ILearnRecordDao getLearnRecordDao() {
		return learnRecordDao;
	}

	public void setLearnRecordDao(ILearnRecordDao learnRecordDao) {
		this.learnRecordDao = learnRecordDao;
	}

	


	public IBranchDao getBranchDao() {
		return branchDao;
	}

	public void setBranchDao(IBranchDao branchDao) {
		this.branchDao = branchDao;
	}

	public LearnRecord findLearnRecordByID(int id) {
		// TODO Auto-generated method stub
		return learnRecordDao.findLearnRecordByID(id);
	}

	public int getResultCount() {
		return learnRecordDao.getResultCount();
	}

	public List<LearnRecord> getLearnRecord(int pageNow, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean saveOrUpdate(LearnRecord learnRecord) {
		return learnRecordDao.saveOrUpdate(learnRecord);
		
	}

	@Override
	public List<LearnRecord> findAllLearnRecordByStudentNO(String studentNo) {
		return learnRecordDao.findAllLearnRecordByStudentNO(studentNo);
	}

	@Override
	public double getLearnTimeSumByStudentNo(String studentNo) {
		List<LearnRecord> list = this.findAllLearnRecordByStudentNO(studentNo);
		double learnTimeSum = 0.0;
		for(int i=0;i<list.size();i++){
			learnTimeSum+=list.get(i).getStudyTime();
		}
		return learnTimeSum;
	}

	@Override
	public List<LearnRecord> getLearnRecordByConditions(
			Map<String, Object> conditions, int pageNow, int pageSize) {
		
		
		String queryString = "from LearnRecord ";
		
		int firstResult = pageSize*(pageNow -1);
		
		if(firstResult < 0) firstResult = 0;
		
		if(conditions == null || conditions.size() <= 0) 
			
			return this.learnRecordDao.getResultsByPage(firstResult, pageSize);
		
		else 
			return null;
		
	}

	@Override
	public List<PersonStudyRecordDTO> queryPersonLearnRecordByYear(Set<Integer> branch_ids,
			String year, String studentNO, String studentName, Integer firstpa,
			Integer secondpa,int pageNow,int pageSize) {
		
		return learnRecordDao.queryPersonLearnRecordByYear(branch_ids, year, studentNO, studentName, firstpa, secondpa, pageNow, pageSize);
	}

	@Override
	public int getStudentCountByCondotions(Set<Integer> branch_ids,
			String year, String studentNO, String studentName, Integer firstpa,
			Integer secondpa) {
		
		return learnRecordDao.getStudentCountByCondotions(branch_ids, year, studentNO, studentName, firstpa, secondpa);
	}
	
	@Override
	public int getBranchCountByCondotions(Set<Integer> branch_ids, String year) {
		
		return learnRecordDao.getBranchCountByCondotions(branch_ids, year);
	}

	@Override
	public List<BranchStudyRecordDTO> getBranchStudyRecordDTOByConditions(
			Set<Integer> branch_ids, String year, int pageNow, int pageSize) {
		
		return learnRecordDao.getBranchStudyRecordDTOByConditions(branch_ids,year,pageNow,pageSize);
	}

	@Override
	public List getStudentStudyTimeByBranchId(int branchId, String year) {
		
		return learnRecordDao.getStudentStudyTimeByBranchId(branchId, year);
	}

	@Override
	public List getStudentStudyTimeByPartyId(Set<Integer> branch_ids, String year) {
		
		return learnRecordDao.getStudentStudyTimeByPartyId(branch_ids, year);
	}

	@Override
	public int getPartyCountByCondotions(Set<Integer> branch_ids, String year) {
		
		return learnRecordDao.getPartyCountByCondotions(branch_ids, year);
	}

	@Override
	public List<PartyStudyRecordDTO> getPartyStudyRecordDTOByConditions(
			Set<Integer> branch_ids, String year, int pageNow, int pageSize) {
		
		return learnRecordDao.getPartyStudyRecordDTOByConditions(branch_ids, year, pageNow, pageSize);
	}

	
	
	
	
}
